package com.fbs.wowo.blockchain.web;

import com.fbs.wowo.base.BaseController;
import com.fbs.wowo.base.Response;
import com.fbs.wowo.blockchain.service.BrowserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/browser")
public class BrowserController extends BaseController {

    @GetMapping("/list")
    public Response list(@RequestParam Integer pageNo, @RequestParam(required = false) Integer pageSize) {
        List transactions = browserService.findTransactions(pageNo, pageSize);
        return success(transactions);
    }

    @GetMapping("/trans")
    public Response trans(@RequestParam String trxId) {
        return success(browserService.findTransaction(trxId));
    }

    @GetMapping("/blockList")
    public Response blockList(@RequestParam Integer pageNo, @RequestParam(required = false) Integer pageSize) {
        return success(browserService.findBlocks(pageNo, pageSize));
    }

    @GetMapping("/stat")
    public Response stat() {
        return success(browserService.statistics());
    }

    // 存证详情
    @GetMapping("/detail")
    public Response detail(@RequestParam String transactionId) {
        return success(browserService.detail(transactionId));
    }

    @GetMapping("/search")
    public Response search(@RequestParam String keyword) throws IOException {
        // 区块，交易，账户
        return success(browserService.search(keyword));
    }

    @Autowired
    private BrowserService browserService;
}
